# -*- coding: utf-8 -*-
# from app.util.LogUtil import log
from PySide2.QtWidgets import *
from PySide2.QtCore import Qt
from PySide2.QtCore import *
from PySide2.QtGui import *
from app.component.util.LayoutUtil import *;

#应该具有QTableWidgetItem的方法和QTableWidget的方法
#行高列宽自适应？
class CustomTableCell(QTableWidget):

    item = None;
    cellStyle = None;

    def __init__(self, parent=None):
        super(CustomTableCell, self).__init__(parent)
        self.cellStyle = CellStyle()
        self.item = QTableWidgetItem()

        self.setFrameShape(QFrame.NoFrame)
        self.setColumnCount(1)
        self.setRowCount(1)
        self.setShowGrid(False)
        self.horizontalHeader().setVisible(False)
        self.verticalHeader().setVisible(False)
        self.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.verticalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.setItem(0, 0, self.item)
        self.setStyleSheet(str(self.cellStyle))
        # style1 = '''
        #     QTableWidget::item {border-bottom: 2px solid red;}
        #     QTableWidget::item:selected {background: #2675BF;}
        # '''
        # self.setStyleSheet(style1)

    def setSelectedBackgroundColor(self, htmlColor):
        self.cellStyle.setSelectedBackground(htmlColor)
        self.setStyleSheet(str(self.cellStyle))

    def setBottomBorder(self, width='', style='', htmlColor='', value=''):
        self.cellStyle.setBottomBorder(width=width, style=style, htmlColor=htmlColor, value=value)
        self.setStyleSheet(str(self.cellStyle))

class CellStyle:
    topBorder = None
    rightBorder = None
    bottomBorder = None
    leftBorder = None
    selectedBackground = '#2675BF'

    def __init__(self):
        pass

    def setTopBorder(self):
        pass;

    def setRightBorder(self):
        pass;

    def setBottomBorder(self, width='', style='', htmlColor='', value=''):
        if self.bottomBorder is None:
            self.bottomBorder = CellBorder.init()

        self.bottomBorder.setCellBorder(name='border-bottom', width=width, style=style, htmlColor=htmlColor, value=value)

    def setLeftBorder(self):
        pass;

    def setSelectedBackground(self, htmlColor):
        self.selectedBackground = htmlColor

    def __str__(self):
        itemRs = 'QTableWidget::item {'
        if self.bottomBorder is not None:
            itemRs+= str(self.bottomBorder)
        itemRs +='}'
        itemRsSelected = 'QTableWidget::item:selected {background:' + self.selectedBackground + ';}'
        return itemRs +'\n'+itemRsSelected

class CellBorder:
    name=''
    width=''
    style=''
    htmlColor=''
    value = ''

    @classmethod
    def init(self):
        return self()

    def __init__(self, **kw):
        pass

    def setCellBorder(self, name='', width='', style='', htmlColor='', value=''):
        self.name = name
        self.width = width
        self.style = style
        self.htmlColor = htmlColor
        self.value = value

    def __str__(self):
        if self.value is not '':
            return self.name +':'+ self.value +';'
        return self.name + ':'+self.width+' '+self.style+' '+self.htmlColor+';'


###################################################################################################
#
# 对话框系列：LR_B
# 左侧、右侧|下方，左侧定宽，下侧定高
#
###################################################################################################
class Custom_LR_B_Widget(QWidget):
    def __init__(self, parent=None, width=200, height=60):
        super(Custom_LR_B_Widget, self).__init__(parent)
        self.qlayout_tb = CustomLayoutManager.layout(CustomLayoutMode.TB)
        self.qlayout_tb.setContentsMargins(0,0,0,0)
        self.qlayout_tb.setSpacing(0)#w1与w2直接的间距
        self.topWidget = QWidget()
        self.bottomWidget = QWidget()
        self.bottomWidget.setMinimumHeight(height)
        self.bottomWidget.setStyleSheet("background:blue;")
        self.qlayout_tb.addWidget(self.topWidget, 1)
        self.qlayout_tb.addWidget(self.bottomWidget)
        if parent is not None:
            parent.setLayout(self.qlayout_tb)
        self.leftWidget = QWidget()
        self.leftWidget.setMinimumWidth(width)
        self.leftWidget.setStyleSheet("background:red;")
        self.rightWdiget = QWidget()
        self.rightWdiget.setStyleSheet("background:green;")
        self.qlayout_lr = CustomLayoutManager.layout(CustomLayoutMode.LR)
        self.qlayout_lr.setContentsMargins(0,0,0,0)
        self.qlayout_lr.setSpacing(0)#w1与w2直接的间距
        self.qlayout_lr.addWidget(self.leftWidget)
        self.qlayout_lr.addWidget(self.rightWdiget, 1)
        self.topWidget.setLayout(self.qlayout_lr)


